<?php

namespace app\common\model;

use think\Model;

class Business extends Model
{
    // 表名
    protected $name = 'business';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'logintime_text',
	    'status_text'
    ];
    
	const STATUS_W = 0;
	const STATUS_Y = 1;
	const STATUS_N = 2;
    
	public static $statusList = [
		self::STATUS_Y => '正常',
		self::STATUS_W => '审核中',
		self::STATUS_N => '已禁用'
	];
	
	public function getStatusTextAttr($value, $data) {
		$value = $value ? $value : $data['status'];
		$list = self::$statusList;
		return isset($list[$value]) ? $list[$value] : '';
	}


    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['logintime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setLogintimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
